package hhh.com.dianming;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class id extends AppCompatActivity implements View.OnClickListener {
   private TextView tv_name;
   private Button bt_check;
    private EditText et_id;
    private String id,name;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_id);
        et_id = (EditText) findViewById(R.id.et_id);
        tv_name = (TextView) findViewById(R.id.tv_name);
        bt_check = (Button) findViewById(R.id.bt_check);
        bt_check.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.bt_check:
                id = et_id.getText().toString().trim();
                if(id.equals("")){
                    Toast.makeText(this,"查询的学号不能为空！",Toast.LENGTH_SHORT).show();
                    return;
                }else {
                    MySqlite mySQLite = new MySqlite(this);
                    SQLiteDatabase database = mySQLite.getReadableDatabase();
                    Cursor cursor = database.rawQuery("select * from mings where user = '" + id + "'", null);
                    if(cursor.getCount() == 0){
                        Toast.makeText(this,"无此学号的学生！",Toast.LENGTH_SHORT).show();
                        return;
                    }else {
                        while (cursor.moveToNext()) {
                            name = cursor.getString(cursor.getColumnIndex("name"));
                        }
                        tv_name.setText(name);
                    }
                }
                break;
        }
    }
}
